cmake_minimum_required(VERSION 3.22)
project(block_test)

set(VAR1 "hello var1") # 创建变量VAR1
set(VAR2 "hello var2") # 创建变量VAR2

# 打印一下变量
message("$ in parent scope: VAR1: ${VAR1}, VAR2: ${VAR2}")

block(SCOPE_FOR VARIABLES POLICIES PROPAGATE VAR1 NEW_VAR)
    message("$ Enter BLOCK")
    message("--$ VAR1 in block scope: ${VAR1}")
    message("--$ VAR2 in block scope: ${VAR2}")

    set(VAR1 "hello somebody") # 设置VAR1的值
    set(NEW_VAR "hello new VAR") # 在block()范围内新建一个变量
    unset(VAR2) # 注销VAR2变量

    message("--$ After modify in block scope")
    message("--$ VAR1 in block scope: ${VAR1}")
    message("--$ VAR2 in block scope: ${VAR2}")
    message("--$ new VAR in block scope: ${NEW_VAR}")
    message("$ Exist BLOCK")
endblock()


# block之外，变量的情况
message("$ VAR1 in parent scope: ${VAR1}")
message("$ VAR2 in parent scope: ${VAR2}")
message("$ new VAR in parent scope: ${NEW_VAR}")